# -*- coding: utf-8 -*-
# time: 2025/4/18 16:24
# file: ch03.py
# author: hanson
import os
from http import HTTPStatus
from dashscope import Application
api_key = "sk-62fb03f9198f4720bb359c873757fafc"

messages = [
    {"role": "system","content":"你是一个幽默的AI助手"},
    {"role": "user","content":"讲个程序员的笑话"}
]

#第一轮
response = Application.call(
    # 若没有配置环境变量，可用百炼API Key将下行替换为：api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中，以减少API Key泄露风险。
    api_key=api_key,
    app_id='e4df880a224c4c3d8a48080ca8a602b4',# 替换为实际的应用 ID
   messages=messages)

joke = response.output.text
print(joke)
# 第二轮

messages.append({"role": "assistant","content":joke})
messages.append({"role": "user","content":"我现在不要笑话了，请模仿李白，来一首类似将进酒风格的诗词，描写秋天的故事"})

response2 = Application.call(
    # 若没有配置环境变量，可用百炼API Key将下行替换为：api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中，以减少API Key泄露风险。
    api_key=api_key,
    app_id='e4df880a224c4c3d8a48080ca8a602b4',# 替换为实际的应用 ID
   messages=messages)

print(response2.output.text)